;(function() {
	'use strict';
	angular.module('controllers.oldOMDisplay.operationDevelop')
		.controller('developNumCtroller', developNumCtroller);

	function developNumCtroller($scope, odService, odOperationDevelop, CoreService,sdsOperationDevelopService,$timeout) {
		$scope.peoples = odService.dnDevelopNum.getPeopleData();
		$scope.sendData = odService.dnDevelopNum.getPageBind();
		//控制查询条件拉上拉下   1为拉下  0 为拉上
		$scope.shoumun = {
			num: 1
		};
		//控制等待样式   false 为隐藏   true 为显示
		$scope._loading.show = false;
		$scope.showChannel = true;
		$scope.queryBusinessName = function(systemCode){
			if(systemCode === '22'){
				$scope.showChannel = false;
			}else {
				$scope.showChannel = true;
			}
			$scope.sendData.business = [];
			sdsOperationDevelopService.qeuryBuinessName({systemCode:systemCode},function(res){
				$scope.contents = res.data;
			});
		};
		$scope.$watch('sendData.business',function(newValue){
			if($scope.sendData.business.length === 0){
				$scope.sendData.channel = [];
				$scope.channels = [{channelName:'天猫'},{channelName:'银行总对总'},{channelName:'移动商城'}];
			}
		});
		$scope.chooseBusChanel = function(code){
			$scope.sendData.channel = [];
			$timeout(function(){
				var codes = $scope.sendData.business.map(function(bus){
					return bus.businessCode;
				});
				if((codes.length === 1 && (codes.indexOf('02') !== -1 || codes.indexOf('03') !== -1)) || (codes.length !== 0 && codes.indexOf('01') === -1)){
					$scope.channels = [{channelName:'银行总对总'}];
				}else {
					$scope.channels = [{channelName:'天猫'},{channelName:'银行总对总'},{channelName:'移动商城'}];
				}
			});
		};
		$scope.init = function(){
			var send = {
				systemCode: $scope.sendData.system
			};
			sdsOperationDevelopService.qeuryBuinessName(send,function(res){
				$scope.contents = res.data;
			});
		};
		var myEcharts = echarts.init(document.getElementById('doc'));
		$scope.search = function() {
			if ($scope.shoumun.num === 1) {
				$scope.shoumun.num = 1;
				return ;
			}
			// return;
			$scope._loading.show = true;
			$scope.send = odOperationDevelop.fmtSendData($scope.sendData);
			$scope.send.developers = [];
			$scope.send.developers = $scope.sendData.people.map(function(p) {
				return p.peopleCode;
			});
			$scope.send.developerName = $scope.sendData.people.map(function(p){
				return p.peopleName;
			});
			var title = odService.dnDevelopNum.getTitle($scope.send);
			$scope.params = {};
			$scope.params.startTime = $scope.send.startTime;
			$scope.params.endTime = $scope.send.endTime;
			myEcharts.clear();
			odService.dnDevelopNum.queryDevelopNum($scope.params, function(res) {
				if (res.state === '10000') {
					var myOption = odService.dnDevelopNum.getEchartsData(res.data,title);
					myEcharts.setOption(myOption);
					$scope._loading.show = false;
					$scope.flag = 'view'
				} else if (res.data!==undefined && res.data.length === 0) {
					$scope.shoumun.num = 1;
					$scope._loading.show = false;
					CoreService.dialog('查询无数据');
				} else {
					$scope.shoumun.num = 1;
					$scope._loading.show = false;
					CoreService.dialog('查询错误');
				}
			});
		};
		// 运维开发完成情况;
		$scope.finish = function() {
			$scope._loading.show = true;
			myEcharts.clear();
			odService.dcDevComplete.queryDevComplete($scope.params, function(res) {
				if (res.state === '10000') {
					var myOption = odService.dcDevComplete.getDevCompleteEchartsPie(res,$scope.send);
					myEcharts.setOption(myOption);
					$scope._loading.show = false;
				} else if (res.data.length === 0) {
					$scope.shoumun.num = 1;
					$scope._loading.show = false;
					CoreService.dialog('查询无数据');
				} else {
					$scope._loading.show = false;
					CoreService.dialog('查询错误');
				}
			});
		};
		// //运维开发完成占比
		$scope.proportion = function() {
			$scope._loading.show = true;
			myEcharts.clear();
			var title = odService.dcDevComplete.getDevCompleteTitle($scope.send, '开发人员占比');
			odService.dpDevProportion.queryDevProportion($scope.params, function(res) {
				if (res.state === '10000') {
					var myOption = odService.getEchartsData(res,title,'developerName','problemCount','开发占比');
					myEcharts.setOption(myOption);
					$scope._loading.show = false;
				} else if (res.data.length === 0) {
					$scope.shoumun.num = 1;
					$scope._loading.show = false;
					CoreService.dialog('查询无数据');
				} else {
					$scope._loading.show = false;
					CoreService.dialog('查询错误');
				}

			});
		};
		//渠道开发分配
		$scope.allocation = function() {
			$scope._loading.show = true;
			myEcharts.clear();
			var title = odService.dcDevComplete.getDevCompleteTitle($scope.send, '渠道开发分配');
			odService.dcdDevChnlDuty.queryDevChnlDuty($scope.params, function(res) {
				if (res.state === '10000') {
					var myOption = odService.getEchartsData(res,title,'channelName','problemCount','渠道分配');
					myEcharts.setOption(myOption);
					$scope._loading.show = false;
				} else if (res.data.length === 0) {
					$scope.shoumun.num = 1;
					$scope._loading.show = false;
					CoreService.dialog('查询无数据');
				} else {
					$scope._loading.show = false;
					CoreService.dialog('查询错误');
				}
			});
		};
		//开发问题数对比
		$scope.problemNum = function(){
			$scope._loading.show = true;
			var title ='';
			var systemName = '';
			$scope.send.systemName.length === 0 ? systemName = '' : systemName = $scope.send.systemName.toString();
			if($scope.send.startTime === $scope.send.endTime){
				title = systemName + $scope.send.startTime.replace(/-/g,'')+'开发问题数对比';
			}else {
				title = systemName + $scope.send.startTime.replace(/-/g,'')+'_'+$scope.send.endTime.replace(/-/g,'')+'各业务问题数对比';
			}
			myEcharts.clear();
			odService.dpDeveloperProblems.queryNum($scope.params,function(res){
				if (res.state === '10000') {
					var myOption = odOperationDevelop.getEchartsData(res.data,title,'time','developerName','problemCount','bar');
					myEcharts.setOption(myOption);
					$scope._loading.show = false;
				}else if(res.data.length ===0) {
					$scope.shoumun.num = 1;
					$scope._loading.show = false;
					CoreService.dialog('查询无数据');
				}else {
					$scope._loading.show = false;
					CoreService.dialog('查询错误');
				}
			});
		};
	}
	developNumCtroller.$inject = ['$scope', 'odService', 'odOperationDevelop', 'CoreService','sdsOperationDevelopService','$timeout'];
})();